#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 7;

int a[N][N], id[N][N], fa[20], vis[N][N], b[N][N];
ll ans;

int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
void merge(int x, int y) { if(!x || !y) return ; fa[gf(x)] = gf(y); }

void dfs(int x, int y) {
	if(x == 4 && y == 5) {
		int tot = 0;
		memset(id, 0, sizeof id);
		rep(i, 1, 4) rep(j, 1, 4) if(vis[i][j]) id[i][j] = ++tot, fa[tot] = tot; else id[i][j] = 0;
		rep(i, 1, 4) rep(j, 1, 4)
			if(vis[i][j])
				merge(id[i][j], id[i - 1][j]), merge(id[i][j], id[i][j - 1]), merge(id[i][j], id[i + 1][j]), merge(id[i][j], id[i][j + 1]);
		int v = 0;
		rep(i, 1, 4) rep(j, 1, 4) if(vis[i][j]) { if(v && v != gf(id[i][j])) return; if(!v) v = gf(id[i][j]); }
		if(v == 0) return;
		tot = 0;
		rep(i, 1, 4) rep(j, 1, 4) if(!vis[i][j]) id[i][j] = ++tot, fa[tot] = tot; else id[i][j] = 0;
		rep(i, 0, 5) rep(j, 0, 5) if(!i || !j || i == 5 || j == 5) id[i][j] = tot + 1; fa[tot + 1] = tot + 1;
		rep(i, 1, 4) rep(j, 1, 4)
			if(id[i][j])
				merge(id[i][j], id[i - 1][j]), merge(id[i][j], id[i][j - 1]), merge(id[i][j], id[i + 1][j]), merge(id[i][j], id[i][j + 1]);
		//ans++; return;
		int t = gf(tot + 1);
		rep(i, 1, 4) rep(j, 1, 4) if(!vis[i][j] && gf(id[i][j]) != t) return;
		ans++; return ;
	}
	if(y == 5) return dfs(x + 1, 1);
	vis[x][y] = 1; dfs(x, y + 1);
	vis[x][y] = 0; if(!a[x][y]) dfs(x, y + 1); vis[x][y] = 0;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	rep(i, 1, 4) rep(j, 1, 4) a[i][j] = in;
	dfs(1, 1); cout << ans << endl;
}
